package data;

/**
 * 队列
 * @author Tang Jiujia
 * @since 10:52 2020-04-08
 */
public class LinkedStringQueue {

    /**
    * 链表大小
    * */
    private int length;
    /**
    *队列头节点
    * */
    private Node head;
    /**
    * 队列尾节点
    * */
    private Node tail;

    /**
     * 入队操作
     *
     * @param value
     * @return boolean
     */
    public boolean enqueue(String value) {
        Node node = new Node(null, null, value);
        if (tail == null) {
            head = node;
        } else {
            tail.next = node;
            node.prev = tail;
        }
        tail = node;
        return true;
    }

    /**
     * 出队操作
     *
     * @param
     * @return java.lang.String
     */
    public String dequeue() {
        String value = null;
        if (head != null) {
            value = head.value;
            head = head.next;
        }
        return value;
    }

    private class Node {
        private Node next;
        private String value;
        private Node prev;

        Node(Node next, Node prev,String value) {
            this.next = next;
            this.prev = prev;
            this.value = value;
        }
    }
}
